<template>
	<view>
		<Sheader :title="'修改密码'" :background="'#fff'" :color="'#203136'"/>
		<view class="content">
			<u-form :model="form" ref="uForm">
				<u-form-item label-width="170" label="旧密码" :required="true">
					<u-input v-model="form.oldPwd" type="password" placeholder="请输入新密码" maxlength="16" :password-icon="false"/>
				</u-form-item>
				<u-form-item label-width="170" label="新密码" :required="true">
					<u-input v-model="form.newPwd" type="password" placeholder="请输入新密码" maxlength="16" :password-icon="false"/>
				</u-form-item>
				<u-form-item label-width="170" label="确认密码" :required="true">
					<u-input v-model="form.passWord2" type="password" placeholder="请再次输入密码" :password-icon="false"/>
				</u-form-item>
			</u-form>
			<view class="register-check">
				<u-icon name="info-circle-fill" color="#2979FF" size="22"></u-icon>
				<text class="register-text">密码由6-16个字符组成，区分大小写（不能是9位以下的纯数字，不能包含空格）</text>
			</view>
			<u-button class="register-btn" type="primary" @click="sendForm">提交</u-button>
		</view>
		<u-toast ref="uToast" />
		<u-modal v-model="showTip" :content="content" :title="title" @confirm="confirm"></u-modal>
	</view>
</template>

<script>
	import Sheader from '@/components/Sheader/index.vue'
	export default {
		data() {
			return {
				showTip: false,
				title: '',
				content: '',
				form: {
					oldPwd: '',
					newPwd: '',
					passWord2: ''
				}
			}
		},
		components: {
			Sheader
		},
		async onLoad() {
		},
		onUnload() {
		},
		methods: {
			async sendForm() {
				if (!this.$utils.isNum(this.form.newPwd) || this.$utils.trim(this.form.newPwd).length < 6) {
					this.content = '新密码不符合规则'
					this.showTip = true
					return false
				}
				if(this.form.newPwd != this.form.passWord2) {
					this.content = '两次密码输入不一致'
					this.showTip = true
					return false
				}
				const res = await this.$http.request('/provider/modifyPwd', this.form, 'post', true, false).then((res) => {
					if (!res.success) {
						this.showTip = true
						this.content = res.msg
						return
					}
					this.title = '修改密码成功'
					this.content = res.msg
					this.showTip = true
				})
			},
			confirm() {
				if (this.title == '修改密码成功') {
					uni.reLaunch({
						url: '/pages/user/index'
					});
				}
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: flex-start;
		background: #fff;
		padding-top: 90rpx;
		height: 100vh;
	}
	.title {
		font-family: YouSheBiaoTiHei;
		margin: 32rpx 0;
		font-size: 48rpx;
		font-weight: 800;
		line-height: 48rpx;
		color: #FFFFFF;
		font-style: oblique;
	}
	/deep/ .u-form-item {
		width: 85vw;
	}
	.register-check {
		height: 54rpx;
		width: 85vw;
		margin: 24rpx;
	}
	.register-btn {
		margin-top: 20rpx;
		width: 85vw;
	}
	.register-text{
		font-size: 22rpx;
		font-family: PingFang SC;
		font-weight: 400;
		line-height: 32rpx;
		color: #2979FF;
		opacity: 1;
		margin-left: 8rpx;
	}
</style>
